package dynamicFolders;

import java.util.Iterator;
import java.util.Vector;


public class Column {
	
	/**
	 * @author Jeroen Mabille
	 */
	
	private String columnName;
	private String title;
	private String tableName;
	private boolean orderBy;
	private boolean desc;
	Vector<Constraint> constraints;
	
	
	public Column(String cName, String tName){		
			this.columnName = cName;
			this.tableName = tName;	
			this.orderBy = false;
			this.desc = false;
			this.constraints = new Vector<Constraint>();
	}		
	
	
	
	public String Constraints(){
		String cons = "";
		Iterator<Constraint> it = this.constraints.iterator();
		if(this.constraints.isEmpty())
			return "";
		else{
			Constraint c = it.next();
			cons += this.getColumnName() + c.getConstraint();
			while(it.hasNext()){
				c = it.next();
				cons += " AND " + this.getColumnName() + c.getConstraint();
			}
			
			return cons;
		}
			
	}
	
	public String getConstraintString(){
		Iterator<Constraint> it = this.constraints.iterator();
		
		String cons = "";
		if(!this.constraints.isEmpty()){
			Constraint c = it.next();
			cons = c.getConstraint();
		}
		return cons;
	}
	
	public void addSmallerConstraint(int v){
		Constraint c = new Constraint();
		c.setConstraint(" < " + v);
		this.addConstraint(c);
	}
	
	public void addSmallerEqualConstraint(int v){
		Constraint c = new Constraint();
		c.setConstraint(" <=  " + v);
		this.addConstraint(c);	
	}
	
	public void addBiggerConstraint(int v){
		Constraint c = new Constraint();
		c.setConstraint(" > " + v);
		this.addConstraint(c);
	}
	
	public void addBiggerEqualConstraint(int v){
		Constraint c = new Constraint();
		c.setConstraint(" >= " + v);
		this.addConstraint(c);
	}
	
	public void addEqualConstraint(String s){
		Constraint c = new Constraint();
		c.setConstraint(" = \"" + s + "\"");
		this.addConstraint(c);
	}
	
	public void addEqualConstraint(int v){
		Constraint c = new Constraint();
		c.setConstraint(" = " + v);
		this.addConstraint(c);
	}
	
	public String getColumnName() {
		return columnName;
	}
	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public boolean isOrderBy() {
		return orderBy;
	}
	public void setOrderBy() {
		this.orderBy = true;
	}
	
	public void addConstraint(Constraint constr){
		this.constraints.add(constr);
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}


	public void setDesc() {
		this.desc = true;
	}
	
	public boolean hasConstraints(){
		return !constraints.isEmpty();
	}


	public boolean isDesc() {
		return desc;
	}
}
